<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button>点击发送GET请求</button>

    <script>
        const btnPost = document.getElementsByTagName('button')[0]
        let isSending = false   //初始发送状态为false
        let xhr = null

        btnPost.onclick = ()=>{
            if(isSending) xhr.abort()   //若正在发送，则上一个请求结束
            xhr = new XMLHttpRequest()  //开始新的请求
            isSending = true

            xhr.open('POST','http://127.0.0.1:8000')
            xhr.send()
            xhr.onreadystatechange = ()=>{
                if(xhr.readyState === 4){
                    if(xhr.status >= 200 &&xhr.status < 300){
                        console.log(xhr.response)
                    }
                }
            }
        }
    </script>
</body>
</html>